home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / xlisp.lbr / XLIO.CQ / xlio.c
Text File  |  1985-06-03  |  3KB  |  130 lines

  1.                          /* xlio - xlisp i/o routines */
  2.  
  3.  
  4. #ifdef CI_86
  5. #include "a:stdio.h"
  6. #include "xlisp.h"
  7. #endif
  8.  
  9. #ifdef AZTEC
  10. #include "a:stdio.h"
  11. #include "xlisp.h"
  12. #endif
  13.  
  14. #ifdef unix
  15. #include <stdio.h>
  16. #include <xlisp.h>
  17. #endif
  18.  
  19.  
  20.                              /* global variables */
  21.  
  22. int (*xlgetc)();
  23. int xlpvals;
  24. int xlplevel;
  25.  
  26.  
  27.                               /* local variables */
  28.  
  29. static int prompt;
  30. static FILE *ifp;
  31.  
  32.  
  33.                  /**********************************************
  34.                  *  tgetc - get a character from the terminal  *
  35.                  **********************************************/
  36.  
  37. static int tgetc()
  38. {
  39.     int ch;
  40.  
  41.     if (prompt)                        /* Prompt if required */
  42.     {
  43.         if (xlplevel > 0)
  44.             printf("%d> ", xlplevel);
  45.         else
  46.             printf("> ");
  47.         prompt = FALSE;
  48.     }
  49.  
  50.     if ((ch = getc(stdin)) == '\n')
  51.         prompt = TRUE;
  52.  
  53.     return (ch);
  54. }
  55.  
  56.  
  57.                        /*********************************
  58.                        *  xltin - setup terminal input  *
  59.                        *********************************/
  60.  
  61. int xltin(flag)
  62.   int flag;
  63. {
  64.     if (flag & !prompt)                /* Flush line if flag set */
  65.         while (tgetc() != '\n')
  66.             ;
  67.  
  68.     prompt = TRUE;
  69.     xlplevel = 0;
  70.     xlgetc = tgetc;
  71.     xlpvals = TRUE;
  72. }
  73.  
  74.  
  75.                    /*****************************************
  76.                    *  fgetcx - get a character from a file  *
  77.                    *****************************************/
  78.  
  79. static int fgetcx()
  80. {
  81.     int ch;
  82.  
  83.     if ((ch = getc(ifp)) <= 0) {
  84.         xlgetc = tgetc;
  85.         xlpvals = TRUE;
  86.         return (tgetc());
  87.     }
  88.  
  89.     return (ch);
  90. }
  91.  
  92.  
  93.                          /*****************************
  94.                          *  xlfin - setup file input  *
  95.                          *****************************/
  96.  
  97. xlfin(str)
  98.   char *str;
  99. {
  100.  
  101. #ifdef DEFEXT
  102.     char fname[100];
  103.  
  104.     strcpy(fname, str);
  105. #else
  106. #define fname str
  107. #endif
  108.  
  109.     if ((ifp = fopen(fname, "r")) != NULL)
  110.     {
  111.         xlgetc = fgetcx;
  112.         xlpvals = FALSE;
  113.         return;
  114.     }
  115.  
  116. #ifdef DEFEXT
  117.     if (strchr(fname, '.') == 0)
  118.         strcat(fname, ".lsp");
  119.  
  120.     if ((ifp = fopen(fname, "r")) != NULL)
  121.     {
  122.         xlgetc = fgetcx;
  123.         xlpvals = FALSE;
  124.         return;
  125.     }
  126. #endif
  127.  
  128.     printf("Can't open \"%s\" for input\n", fname);
  129. }
  130.